<%var jstpl = {%>
    <script>
        layui.use('table', function() {
            var table = layui.table;

            //第一个实例
            table.render({
                elem: '#list',
                url: '/system/banner/list' //数据接口
                    ,
                page: false //开启分页
                    ,
                method: 　 'POST'
                    // ,toolbar: 'default'
                    // ,where: {shop_id:""}
                    // ,request: {
                    //     pageName: 'pageNumber' //页码的参数名称，默认：page
                    //     ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
                    // }
                    ,
                parseData: function(res) { //res 即为原始返回的数据
                    // console.info(res);
                    return {
                        "code": 0, //解析接口状态
                        "msg": "", //解析提示文本
                        "count": res.data.length, //解析数据长度
                        "data": res.data //解析数据列表
                    };
                },
                cols: [
                    [ //表头
                        {
                            field: 'img',
                            title: '轮播图',
                            templet: "#img"
                        }, {
                            field: 'title',
                            title: '标题'
                        }, {
                            field: 'state',
                            title: '状态',
                            templet: "#state"
                        }, {
                            field: 'sort',
                            title: '排序'
                        }, {
                            field: 'createtime',
                            title: '创建时间',
                            templet: "<div>{{layui.util.toDateString(d.createtime,'yyyy-MM-dd HH:mm:ss')}}</div>"
                        }, {
                            field: 'right',
                            toolbar: '#barDemo'
                        }
                    ]
                ]
            });
            //监听行工具事件
            table.on('tool(list)', function(obj) {
                var data = obj.data;
                // console.log(data);
                if (obj.event === 'del') {
                    layer.confirm('是否删除此轮播图？', function(index) {
                        Ajax("/system/banner/delete/" + data.id, function(ret) {
                            if (ret.state) {
                                obj.del();
                            } else {
                                layer.msg(ret.msg);
                            }
                        });
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    location.href = "/system/banner/add/" + data.id;
                }
            });
        });
    </script>
    <%};%>
        <% var csstpl={ %>
            <style>
                .layui-table-cell {
                    height: auto!important;
                    white-space: normal;
                }
            </style>
            <% }; %>
                <%layout("../layout/_layout_layui.html",{title:'轮播图管理',jstpl:jstpl,csstpl:csstpl}){ %>
                    <div class="layui-row">
                        <a href="/system/banner/add" class="layui-btn">添加轮播图</a>
                        <div class="layui-col-md12" style="margin-top: 20px">
                            <table id="list" lay-filter="list"></table>
                        </div>
                    </div>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                    <script type="text/html" id="img">
                        <img src="{{d.img}}" onclick="gx.photos('{{d.title}}','{{d.img}}')">
                    </script>
                    <script type="text/html" id="state">
                        {{# if(d.state==1){ }}
                        <label class="layui-badge layui-bg-blue">正常</label> {{# }else{ }}
                        <label class="layui-badge layui-bg-red">禁用</label> {{# } }}
                    </script>
                    <%};%>